package com.lht.testDemo;

import java.util.Random;

/**
 * <p>
 * 把一个int 类型转换成String
 * String.vavlueOf ()
 * int+""
 * 性能比较
 * </p>
 *
 * @author Eric
 * @version 1.0
 * @date 2019-05-24
 */
public class StringValueOfAppendTest {


    public static void main(String[] args) {


        Random random = new Random();

        int[] arr = new int[100000];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = random.nextInt(1000);
        }

        Long start = System.currentTimeMillis();
        for (int i = 0; i < arr.length; i++) {
            String a = String.valueOf(arr[i]);
        }
        Long end = System.currentTimeMillis();
        Long count = end - start;
        System.out.println("String.valueOf():" + count);

        start = System.currentTimeMillis();
        for (int i = 0; i < arr.length; i++) {
            String a = arr[i] + "";
        }
        end = System.currentTimeMillis();
        count = end - start;
        System.out.println("+'':" + count);
    }

}
